export const useStorage = () => ({
    setItem<T>(key: string, val: T): void {
        const storage = this.getStorage()
        storage[key] = val
        window.localStorage.setItem("fromsko", JSON.stringify(storage))
    },
    getItem<T>(key: string): T | undefined {
        const storage = this.getStorage()
        const value = storage[key]
        return value as T | undefined
    },
    getStorage(): Record<string, unknown> {
        return JSON.parse(window.localStorage.getItem("fromsko") || "{}")
    },
    clearItem(key: string): void {
        const storage = this.getStorage()
        delete storage[key]
        window.localStorage.setItem("fromsko", JSON.stringify(storage))
    },
    clearAll(): void {
        window.localStorage.clear()
    },
})
